package com.jky.stmall.manger.entity;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * 服务器向客户端返回的数据
 */
@Data //与@Getter和@Setter
@ToString
@NoArgsConstructor
public class Result {
    //操作的状态吗
    private Integer code;
    //返回的错误信息
    private String msg;
    //查询的结果
    private Object data;
    //静态方法
    public static Result success(Integer code ,String msg,Object data){
        Result  result= new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return  result;
    }
    public  static  Result success(Object data){
        return  success(0,null,data);
    }
    public  static Result success(){
        return success(0,null,null);
    }
    public static Result error(Integer code,String msg,Object data){
        Result result= new Result();
        result.setCode(code);
        result.setData(data);
        result.setMsg(msg);
        return result;
    }
    public static Result error(Integer code,String msg){
        return  error(code,msg,null);
    }
    public static Result error(String msg){
        return error(-1,msg,null);
    }
}
